package com.qinghuan.designMode.prePrinciple.ocp.improve;

/**
 * @Auther: qinghuan
 * @Date: 2022/2/21 20:11
 * @Description:
 */
public class Ocp {

    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Circle());
    }

}

//使用方（不可修改）
class GraphicEditor {
    public void drawShape(Shape shape) {
        shape.draw();
    }
}

//拓展方（可修改）
abstract class Shape {
    int m_type;

    public abstract void draw();
}

class Rectangle extends Shape {
    @Override
    public void draw() {
        System.out.println(" 绘制长方形");
    }
}

class Circle extends Shape {
    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

class Triangle extends Shape {
    @Override
    public void draw() {
        System.out.println(" 绘制三角形");
    }
}